//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    mails: []
  },
  onLoad: function () {
    var session = wx.getStorageSync('session')
    if (!session) {
      wx.redirectTo({
        url: '../login/login'
      })
    }
  },
  onShow() {
    var self = this;
    wx.request({
      url: app.globalData.baseUrl + 'users/query',
      data: {
        session: wx.getStorageSync("session")
      },
      method: "POST",
      success: function (res) {
        console.log(res.data);
        if (res.data.code === '000000') {
          self.setData({
            mails: res.data.body
          });
        }
      }
    })
  },
  createEmail: function() {
    wx.navigateTo({
      url: '../write/write',
    })
  },
  opened: function() {
    wx.navigateTo({
      url: '../opened/opened',
    })
  },
  openMail: function(event) {
    wx.navigateTo({
      url: '../open/open?id=' + event.currentTarget.dataset.id,
    })
  }
})
